home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-03
/
himath.zip
/
MATHDEMO.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-10-04
|
25KB
|
639 lines
'***************************************************************************
'**** MATHDEMO.BAS Test Kevin Jorgensen's "HIMATH" Library
'***************************************************************************
DEFDBL A-Z
CONST Pi = 3.141592653589793#
CONST HalfPi = Pi / 2#
CONST TwoPi = Pi * 2#
TYPE VRect 'User type for 3d Vector Math
x AS DOUBLE
y AS DOUBLE
z AS DOUBLE
END TYPE
TYPE XRect 'User Type for Complex Numbers
i AS DOUBLE
j AS DOUBLE
END TYPE
'======================================================================
'Math Demo Routines
'======================================================================
DECLARE SUB TestHold ()
DECLARE SUB TestMatrix1 ()
DECLARE SUB TestMatrix2 ()
DECLARE SUB TestMatrixLoad (GivenMtx#(), A$)
DECLARE SUB TestMatrixPrint (MtxErr%, Mtx())
DECLARE SUB TestInvTrig ()
DECLARE SUB TestTriangle ()
DECLARE SUB TestTriangle2 (s$, p1#, p2#, p3#)
DECLARE SUB TestVector ()
DECLARE SUB TestVectorLoad (GivenVctr AS ANY, A$)
DECLARE SUB TestVectorPrint (GivenVctr AS ANY)
DECLARE SUB TestXmath ()
DECLARE SUB TestXMatrix1 ()
DECLARE SUB TestXMatrix2 ()
DECLARE SUB TestXMatrixLoad (GivenMtx() AS XRect, A$)
DECLARE SUB TestXMatrixPrint (MtxErr%, Mtx() AS XRect)
'======================================================================
'======================================================================
'Demo'd in TestInvTrig
DECLARE FUNCTION ACOS (x)
DECLARE FUNCTION ASIN (y)
DECLARE FUNCTION ATAN2 (x, y)
'Demo'd in TestTriangle
DECLARE SUB TriangleSolve (ProbType$, p1, p2, p3, A(), s(), NbrOfSolutions%)
'Demo'd in TestMatrix1
DECLARE SUB MtxCoeff (MtxErr%, Mtx(), Vctr(), Coeff())
DECLARE SUB MtxCoeffA (MtxErr%, Mtx())
DECLARE SUB MtxCopy (MtxErr%, Src(), Dst())
DECLARE FUNCTION MtxDet (MtxErr%, Mtx())
'Demo'd in TestMatrix2
DECLARE SUB MtxAdd (MtxErr%, A(), B(), C())
DECLARE SUB MtxSub (MtxErr%, A(), B(), C())
DECLARE SUB MtxInv (MtxErr%, A(), B())
DECLARE SUB MtxMltS (MtxErr%, A(), B, C())
DECLARE SUB MtxMltX (MtxErr%, A(), B(), C())
'Demo'd in TestXmath
DECLARE SUB XCnvP (r, t, Result AS XRect)
DECLARE SUB XCnvR (i, j, Result AS XRect)
DECLARE FUNCTION XMag (Op1 AS XRect)
DECLARE FUNCTION XAng (Op1 AS XRect)
DECLARE FUNCTION XReal (Op1 AS XRect)
DECLARE FUNCTION XImag (Op1 AS XRect)
DECLARE FUNCTION XFmtP$ (Op1 AS XRect)
DECLARE FUNCTION XFmtR$ (Op1 AS XRect)
DECLARE SUB XAdd (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XSub (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XMlt (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XDiv (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XPwr (Op1 AS XRect, Op2, Result AS XRect)
DECLARE SUB XCnj (Op1 AS XRect, Result AS XRect)
DECLARE SUB XInv (Op1 AS XRect, Result AS XRect)
'Demo'd in TestXMatrix1
DECLARE SUB XMtxCoeff (MtxErr%, Mtx() AS XRect, Vctr() AS XRect, Coeff() AS XRect)
DECLARE SUB XMtxCoeffA (MtxErr%, Mtx() AS XRect)
DECLARE SUB XMtxCopy (MtxErr%, Src() AS XRect, Dst() AS XRect)
DECLARE SUB XMtxDet (MtxErr%, XMtx() AS XRect)
'Demo'd in TestXMatrix2
DECLARE SUB XMtxAdd (MtxErr%, A() AS XRect, B() AS XRect, C() AS XRect)
DECLARE SUB XMtxInv (MtxErr%, A() AS XRect, Mtx() AS XRect)
DECLARE SUB XMtxMltS (MtxErr%, A() AS XRect, B AS XRect, C() AS XRect)
DECLARE SUB XMtxMltX (MtxErr%, A() AS XRect, B() AS XRect, C() AS XRect)
DECLARE SUB XMtxSub (MtxErr%, A() AS XRect, B() AS XRect, C() AS XRect)
'Demo'd in TestVector
DECLARE SUB VAdd (Op1 AS VRect, Op2 AS VRect, Result AS VRect)
DECLARE SUB VMltX (Op1 AS VRect, Op2 AS VRect, Result AS VRect)
DECLARE SUB VSub (Op1 AS VRect, Op2 AS VRect, Result AS VRect)
DECLARE FUNCTION VMltD (Op1 AS VRect, Op2 AS VRect)
'======================================================================
RANDOMIZE TIMER
TestInvTrig
TestTriangle
TestMatrix1
TestMatrix2
TestXmath
TestXMatrix1
TestXMatrix2
TestVector
END
'======================================================================
SUB TestHold
'======================================================================
PRINT "Press Enter to Continue ";
x = CSRLIN
DO
LOOP UNTIL INKEY$ <> ""
LOCATE x, 1: PRINT SPACE$(40)
END SUB
'======================================================================
SUB TestInvTrig
'======================================================================
CLS
PRINT "SUB TestInvTrig Demonstrating of ASIN, ACOS, and ATAN functions"
PRINT
PRINT "Given --------------------------- Calc'd -------------------"
PRINT "ang SIN COS TAN ASIN ACOS ATAN"
PRINT "--- ------- ------- ------------ -------- -------- --------"
FOR x = 0 TO 360 STEP 30
t = x / 180 * Pi
xsin = SIN(t)
xcos = COS(t)
xtan = TAN(t)
ysin = ASIN(xsin) * 180# / Pi
ycos = ACOS(xcos) * 180# / Pi
ytan = ATAN2(xcos, xsin) * 180# / Pi
IF ABS(xtan) >= 0 AND ABS(xtan) < 99999 THEN
PRINT USING "### ##.#### ##.#### #####.###### ####.### ####.### ####.###"; x; xsin; xcos; xtan; ysin; ycos; ytan
ELSE
PRINT USING "### ##.#### ##.#### ##.#####^^^^ ####.### ####.### ####.###"; x; xsin; xcos; xtan; ysin; ycos; ytan
END IF
NEXT x
TestHold
END SUB
'======================================================================
SUB TestMatrix1
'======================================================================
Rows% = 8: ColVctr% = Rows% + 1
DIM ScratchMtx(Rows%, ColVctr%), GivenMtx(Rows%, ColVctr%)
DIM ScratchMtx2(Rows%, Rows%), Vctr(Rows%), Coeff(Rows%)
CLS
PRINT "SUB TestMatrix1 Demonstrating MtxCoeff, MtxCoeffA, MtxCopy, MtxDet"
TestMatrixLoad GivenMtx(), "A"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Determinant using MtxDet ═════════════════════════════════════"
MtxCopy MtxErr%, GivenMtx(), ScratchMtx()
PRINT "║ Determinant = "; MtxDet(MtxErr%, ScratchMtx())
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Coefficients using MtxCoeffA ═════════════════════════════════"
'The Column Vector Must be in the last colum of the array
'ie. if the matrix is 5x5, the colum vector should be in column 6
MtxCopy MtxErr%, GivenMtx(), ScratchMtx()
MtxCoeffA MtxErr%, ScratchMtx()
'TestMatrixPrint MtxErr%, ScratchMtx()
PRINT "║";
FOR i% = 1 TO Rows%
PRINT USING " ##.####"; ScratchMtx(i%, ColVctr%);
NEXT i%
PRINT
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Coefficients using MtxCoeff ═════════════════════════════════"
FOR i% = 1 TO Rows%
Vctr(i%) = GivenMtx(i%, ColVctr%)
NEXT i%
MtxCopy MtxErr%, GivenMtx(), ScratchMtx2()
MtxCoeff MtxErr%, ScratchMtx2(), Vctr(), Coeff()
PRINT "║";
FOR i% = 1 TO Rows%
PRINT USING " ##.####"; Coeff(i%);
NEXT i%
PRINT
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
END SUB
'======================================================================
SUB TestMatrix2
'======================================================================
DIM MtxA(3, 3), MtxB(3, 3), MtxC(3, 3)
'======================================================================
CLS
PRINT "SUB TestMatrix2 Demonstrating MtxAdd"
TestMatrixLoad MtxA(), "A"
TestMatrixLoad MtxB(), "B"
MtxAdd Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Sum of two Matrices using MtxAdd ═════════════════════════════"
TestMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "SUB TestMatrix2 Demonstrating MtxSub"
TestMatrixLoad MtxA(), "A"
TestMatrixLoad MtxB(), "B"
MtxSub Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Difference of two Matrices (A-B) using MtxSub ═════════════════"
TestMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "SUB TestMatrix2 Demonstrating MtxInv"
TestMatrixLoad MtxA(), "A"
MtxCopy Merr%, MtxA(), MtxB()
MtxInv Merr%, MtxA(), MtxC()
PRINT "╔══ Calculate Inverse of Matrix using MtxInv ═══════════════════════════════"
TestMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
MtxInv Merr%, MtxC(), MtxA()
PRINT "╔══ Calculate Inverse of Inverse using MtxInv ═══════════════════════════════"
TestMatrixPrint Merr%, MtxA()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "SUB TestMatrix2 Demonstrating MtxMltX"
TestMatrixLoad MtxA(), "A"
TestMatrixLoad MtxB(), "B"
MtxMltX Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Matrix Cross Product (AxB) ═══════════════════════════════════"
TestMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "SUB TestMatrix2 Demonstrating MtxMltS"
TestMatrixLoad MtxA(), "A"
Scalar# = 20 * RND - 10
PRINT
PRINT "Scalar = "; Scalar#
PRINT
MtxMltS Merr%, MtxA(), Scalar#, MtxC()
PRINT "╔══ Calculate Matrix Scalar Product (A∙B) ═══════════════════════════════════"
TestMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
END SUB
'======================================================================
SUB TestMatrixLoad (GivenMtx(), A$)
'======================================================================
PRINT "╔══ Generating ORIGINAL MATRIX '"; A$; "' ══════════════════════════════════════════"
Rows% = UBOUND(GivenMtx, 1)
Cols% = UBOUND(GivenMtx, 2)
FOR row% = 1 TO Rows%
FOR col% = 1 TO Cols%
GivenMtx(row%, col%) = RND * 20 - 10
NEXT col%
NEXT row%
TestMatrixPrint MtxErr%, GivenMtx()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
END SUB
'===========================================================================
SUB TestMatrixPrint (MtxErr%, Mtx())
'===========================================================================
MtxErr% = 1
Rows% = UBOUND(Mtx, 1): Cols% = UBOUND(Mtx, 2)
ColWidth% = 74 / Cols%
f$ = STRING$(ColWidth%, "#")
MID$(f$, (ColWidth% + 1) / 2, 1) = "."
IF ColWidth% > 15 THEN f$ = RIGHT$(SPACE$(ColWidth%) + "#######.#######", ColWidth%)
MtxErr% = 0
DispStartRow% = CSRLIN
IF (DispStartRow% + Rows% + 1) > 24 THEN CLS : DispStartRow% = 1
PRINT " ";
FOR col% = 1 TO Cols%
PRINT USING SPACE$(ColWidth% - 2) + "##"; col%;
NEXT col%
PRINT : PRINT " ";
FOR col% = 1 TO Cols%
PRINT " "; STRING$(ColWidth% - 1, "-");
NEXT col%
FOR row% = 1 TO Rows%
LOCATE DispStartRow% + row% + 1, 1: PRINT USING "##: "; row%;
NEXT row%
FOR row% = 1 TO Rows%
FOR col% = 1 TO Cols%
LOCATE row% + DispStartRow% + 1, (col% - 1) * ColWidth% + 5
PRINT USING f$; Mtx(row%, col%)
NEXT col%
NEXT row%
END SUB
'======================================================================
SUB TestTriangle
'======================================================================
DIM GivenSide(3), GivenAngle(3)
'======================================================================
CLS
PRINT "SUB TestTriangle Demonstrating TriangleSolve"
PRINT
TriangleSolve "SSS", 3#, 4#, 5#, GivenAngle(), GivenSide(), Solutions%
TestTriangle2 "SAS", (GivenSide(1)), (GivenAngle(3)), (GivenSide(2))
TestTriangle2 "ASA", (GivenAngle(1)), (GivenSide(3)), (GivenAngle(2))
TestTriangle2 "AAS", (GivenAngle(1)), (GivenAngle(2)), (GivenSide(1))
TestHold
CLS
PRINT "SUB TestTriangle Demonstrating TriangleSolve"
PRINT
TestTriangle2 "SAS", (GivenSide(1)), (GivenAngle(3)), (GivenSide(2))
TestTriangle2 "SSA", (GivenSide(1)), (GivenSide(2)), (GivenAngle(1))
TestTriangle2 "SSS", (GivenSide(1)), (GivenSide(2)), (GivenSide(3))
TestHold
END SUB
'======================================================================
SUB TestTriangle2 (s$, p1, p2, p3)
'======================================================================
DIM CalcAngle(3), CalcSide(3)
'======================================================================
PRINT "╔════════════════════════════════════════════════════════════════════════"
SELECT CASE s$
CASE "ASA"
x1 = p1 * 180 / Pi: x2 = p2: x3 = p3 * 180 / Pi
PRINT USING "║Given: ASA, ####.####(Angle 1) ####.####( Side 3) ####.####(Angle 2)"; x1; x2; x3
CASE "AAS"
x1 = p1 * 180 / Pi: x2 = p2 * 180 / Pi: x3 = p3
PRINT USING "║Given: AAS, ####.####(Angle 1) ####.####(Angle 2) ####.####( Side 1)"; x1; x2; x3
CASE "SAS"
x1 = p1: x2 = p2 * 180 / Pi: x3 = p3
PRINT USING "║Given: SAS, ####.####( Side 1) ####.####(Angle 3) ####.####( Side 2)"; x1; x2; x3
CASE "SSA"
x1 = p1: x2 = p2: x3 = p3 * 180 / Pi
PRINT USING "║Given: SSA, ####.####( Side 1) ####.####( Side 2) ####.####(Angle 1)"; x1; x2; x3
CASE "SSS"
x1 = p1: x2 = p2: x3 = p3
PRINT USING "║Given: SSS, ####.####( Side 1) ####.####( Side 2) ####.####( Side 3)"; x1; x2; x3
CASE ELSE
END SELECT
FOR try% = 1 TO 2
PRINT "╟──────────────────────────────────────────────────────────────────────"
IF Solutions% = 2 THEN PRINT "║ **** SECOND SOLUTION ****"
TriangleSolve s$, p1, p2, p3, CalcAngle(), CalcSide(), Solutions%
PRINT USING "║Results: ###.####( Side 1) ###.####( Side 2) ###.####( Side 3)"; CalcSide(1); CalcSide(2); CalcSide(3)
PRINT USING "║Results: ###.####(Angle 1) ###.####(Angle 2) ###.####(Angle 3)"; CalcAngle(1) / Pi * 180; CalcAngle(2) / Pi * 180; CalcAngle(3) / Pi * 180
IF Solutions% = 1 THEN EXIT FOR
NEXT try%
PRINT "╚════════════════════════════════════════════════════════════════════════"
END SUB
'======================================================================
SUB TestVector
'======================================================================
DIM VctrA AS VRect, VctrB AS VRect, VctrC AS VRect
'======================================================================
CLS
PRINT "SUB TestVector Demonstrating VAdd, VSub, VMltX, VMltD"
TestVectorLoad VctrA, "A"
TestVectorLoad VctrB, "B"
VAdd VctrA, VctrB, VctrC
PRINT "╔══ Calculate Sum of two Vectors using VAdd ═════════════════════════════"
TestVectorPrint VctrC
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
VSub VctrA, VctrB, VctrC
PRINT "╔══ Calculate Difference of two Vectors (A-B) using VSub ═════════════════"
TestVectorPrint VctrC
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
VMltX VctrA, VctrB, VctrC
PRINT "╔══ Calculate Vector Cross Product (AxB) using VMltX ════════════════════"
TestVectorPrint VctrC
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
PRINT "╔══ Calculate Vector Dot Product (A∙B) ═════════════════════════════════════"
PRINT VMltD(VctrA, VctrB)
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
END SUB
'======================================================================
SUB TestVectorLoad (GivenVctr AS VRect, A$)
'======================================================================
PRINT "╔══ Generating ORIGINAL Vector '"; A$; "' ══════════════════════════════════════════"
GivenVctr.x = RND * 20 - 10
GivenVctr.y = RND * 20 - 10
GivenVctr.z = RND * 20 - 10
TestVectorPrint GivenVctr
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
END SUB
'======================================================================
SUB TestVectorPrint (GivenVctr AS VRect)
'======================================================================
PRINT USING "+###.####x+###.####y+###.####z"; GivenVctr.x; GivenVctr.y; GivenVctr.z
END SUB
'======================================================================
SUB TestXmath
'======================================================================
DIM Op1 AS XRect, Op2 AS XRect, Result AS XRect
'======================================================================
CLS
PRINT "SUB TestXmath Demonstrating Complex Arithmetic Functions"
PRINT
i = 20 * RND - 10: j = 20 * RND - 10
XCnvR i, j, Op1
PRINT "Given Op1 = "; XFmtR(Op1), XFmtP(Op1)
r = 20 * RND - 10: t = TwoPi * RND - Pi
XCnvP r, t, Op2
PRINT "Given Op2 = "; XFmtR(Op2), XFmtP(Op2)
PRINT
PRINT "Magnitude XMag(Op1) "; XMag(Op1)
PRINT "Angle XAng(Op1) "; XAng(Op1), XAng(Op1) * 180 / Pi; "°"
PRINT "Real XReal(Op1) "; XReal(Op1)
PRINT "Imaginary XImag(Op1) "; XImag(Op1)
PRINT
PRINT "Magnitude XMag(Op2) "; XMag(Op2)
PRINT "Angle XAng(Op2) "; XAng(Op2), XAng(Op2) * 180 / Pi; "°"
PRINT "Real XReal(Op2) "; XReal(Op2)
PRINT "Imaginary XImag(Op2) "; XImag(Op2)
PRINT
XAdd Op1, Op2, Result: PRINT "Add Xadd(Op1,Op2) "; XFmtP$(Result); TAB(55); XFmtR$(Result)
XSub Op1, Op2, Result: PRINT "Subtract XSub(Op1,Op2) "; XFmtP$(Result); TAB(55); XFmtR$(Result)
XMlt Op1, Op2, Result: PRINT "Multiply XMlt(Op1,Op2) "; XFmtP$(Result); TAB(55); XFmtR$(Result)
XDiv Op1, Op2, Result: PRINT "Divide XDiv(Op1,Op2) "; XFmtP$(Result); TAB(55); XFmtR$(Result)
XPwr Op1, Op2.i, Result: PRINT "Power XPwr(Op1,Op2.i)"; XFmtP$(Result); TAB(55); XFmtR$(Result)
XCnj Op1, Result: PRINT "Conjugate XCnj(Op1) "; XFmtP$(Result); TAB(55); XFmtR$(Result)
XInv Op1, Result: PRINT "Inverse XInv(Op1) "; XFmtP$(Result); TAB(55); XFmtR$(Result)
TestHold
END SUB
'======================================================================
SUB TestXMatrix1
'======================================================================
Rows% = 3: ColVctr% = Rows% + 1
DIM ScratchMtx(Rows%, ColVctr%) AS XRect
DIM GivenMtx(Rows%, ColVctr%) AS XRect
DIM ScratchMtx2(Rows%, Rows%) AS XRect
DIM Vctr(Rows%) AS XRect
DIM Coeff(Rows%) AS XRect
'======================================================================
CLS
PRINT "Demonstrating XMtxCoeff, XMtxCopy, XMtxDet "
TestXMatrixLoad GivenMtx(), "A"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Determinant using MtxDet ═════════════════════════════════════"
XMtxCopy MtxErr%, GivenMtx(), ScratchMtx()
XMtxDet MtxErr%, ScratchMtx()
PRINT "║ Determinant = "; XFmtR(ScratchMtx(0, 0))
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Coefficients using XMtxCoeffA ═════════════════════════════════"
'The Column Vector Must be in the last colum of the array
'ie. if the matrix is 5x5, the colum vector should be in column 6
XMtxCopy MtxErr%, GivenMtx(), ScratchMtx()
XMtxCoeffA MtxErr%, ScratchMtx()
PRINT "║";
FOR i% = 1 TO Rows%
PRINT " "; XFmtR(ScratchMtx(i%, ColVctr%));
NEXT i%
PRINT
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Coefficients using MtxCoeff ═════════════════════════════════"
FOR i% = 1 TO Rows%
Vctr(i%) = GivenMtx(i%, ColVctr%)
NEXT i%
XMtxCopy MtxErr%, GivenMtx(), ScratchMtx2()
XMtxCoeff MtxErr%, ScratchMtx2(), Vctr(), Coeff()
PRINT "║";
FOR i% = 1 TO Rows%
PRINT " "; XFmtR(Coeff(i%));
NEXT i%
PRINT
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
END SUB
'======================================================================
SUB TestXMatrix2
'======================================================================
DIM MtxA(3, 3) AS XRect, MtxB(3, 3) AS XRect, MtxC(3, 3) AS XRect
DIM Scalar AS XRect
'======================================================================
CLS
PRINT "Demonstrating XMtxAdd, XMtxSub, XMtxInv, XMtxMltX, XMtxMltS"
TestXMatrixLoad MtxA(), "A"
TestXMatrixLoad MtxB(), "B"
XMtxAdd Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Sum of two Matrices using XMtxAdd ═════════════════════════════"
TestXMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "Demonstrating XMtxAdd, XMtxSub, XMtxInv, XMtxMltX, XMtxMltS"
TestXMatrixLoad MtxA(), "A"
TestXMatrixLoad MtxB(), "B"
XMtxSub Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Difference of two Matrices (A-B) using MtxSub ═════════════════"
TestXMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "Demonstrating XMtxAdd, XMtxSub, XMtxInv, XMtxMltX, XMtxMltS"
TestXMatrixLoad MtxA(), "A"
XMtxCopy Merr%, MtxA(), MtxB()
XMtxInv Merr%, MtxA(), MtxC()
PRINT "╔══ Calculate Inverse of Complex Matrix using XMtxInv ══════════════════════"
TestXMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
XMtxInv Merr%, MtxC(), MtxA()
PRINT "╔══ Calculate Complex Inverse of Inverse using XMtxInv ═════════════════════"
TestXMatrixPrint Merr%, MtxA()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "Demonstrating XMtxAdd, XMtxSub, XMtxInv, XMtxMltX, XMtxMltS"
TestXMatrixLoad MtxA(), "A"
TestXMatrixLoad MtxB(), "B"
XMtxMltX Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Complex Matrix Cross Product (AxB) using XMtxMltX ════════════"
TestXMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
CLS
PRINT "Demonstrating XMtxAdd, XMtxSub, XMtxInv, XMtxMltX, XMtxMltS"
TestXMatrixLoad MtxA(), "A"
Scalar.i = 20 * RND - 10
Scalar.j = 20 * RND - 10
PRINT
PRINT "Scalar = "; XFmtR(Scalar)
PRINT
XMtxMltS Merr%, MtxA(), Scalar, MtxC()
PRINT "╔══ Calculate Complex Matrix Scalar Product (A∙B) using XMtxMltS ═══════════"
TestXMatrixPrint Merr%, MtxC()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
END SUB
'======================================================================
SUB TestXMatrixLoad (GivenMtx() AS XRect, A$)
'======================================================================
PRINT "╔══ Generating ORIGINAL MATRIX '"; A$; "'═══════════════════════════════════════════"
Rows% = UBOUND(GivenMtx, 1)
Cols% = UBOUND(GivenMtx, 2)
FOR row% = 1 TO Rows%
FOR col% = 1 TO Cols%
GivenMtx(row%, col%).i = RND * 20 - 10
GivenMtx(row%, col%).j = RND * 20 - 10
NEXT col%
NEXT row%
TestXMatrixPrint MtxErr%, GivenMtx()
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
END SUB
'===========================================================================
SUB TestXMatrixPrint (MtxErr%, Mtx() AS XRect)
'===========================================================================
MtxErr% = 1
Rows% = UBOUND(Mtx, 1): Cols% = UBOUND(Mtx, 2)
ColWidth% = 74 / Cols%
MtxErr% = 0
DispStartRow% = CSRLIN
IF (DispStartRow% + Rows% + 1) > 24 THEN CLS : DispStartRow% = 1
PRINT " ";
FOR col% = 1 TO Cols%
PRINT USING SPACE$(ColWidth% - 2) + "##"; col%;
NEXT col%
PRINT : PRINT " ";
FOR col% = 1 TO Cols%
PRINT " "; STRING$(ColWidth% - 1, "-");
NEXT col%
FOR row% = 1 TO Rows%
LOCATE DispStartRow% + row% + 1, 1: PRINT USING "##: "; row%;
NEXT row%
FOR row% = 1 TO Rows%
FOR col% = 1 TO Cols%
LOCATE row% + DispStartRow% + 1, (col% - 1) * ColWidth% + 5
PRINT USING "+##.###+##.###j"; Mtx(row%, col%).i; Mtx(row%, col%).j
NEXT col%
NEXT row%
END SUB